home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / MPW Related / MPW Script Tips 1.1.1 / Sample Scripts / SearchAll < prev    next >
Encoding:
Text File  |  1991-08-16  |  3.0 KB  |  86 lines  |  [TEXT/MPS ]

  1. #----------------------------------------------------------------------------------------------------------------------------------------------------
  2. #    SearchAll
  3. #    MPW Shell Script
  4. #    Written by Gina Cherry • August 16, 1991
  5. #    Copyright:    © 1991 by Apple Computer, Inc., all rights reserved.
  6. #    
  7. #    Usage: 
  8. #        SearchAll pattern [pathName…][-b][-i|-s][-nf][-ns][-sf][-q][-r][-f file]
  9. #        
  10. #    Function:
  11. #        SearchAll will search for a given pattern in all files specified in pathName.  The pattern can
  12. #        be a string or a regular expression.  If pathName is a directory, SearchAll will search all files 
  13. #        in that directory recursively.  If no path name is specified, SearchAll will search the current 
  14. #        directory. The options for SearchAll are the same as the options for the MPW tool Search 
  15. #        (see the MPW Command Reference for more information).
  16. #        
  17. #
  18. #    Note:
  19. #        The pattern must appear before the path name on the command line.
  20. #----------------------------------------------------------------------------------------------------------------------------------------------------
  21.  
  22. #    Don't exit on error.
  23.     Set Exit 0
  24.     
  25. #    Initialize variables.
  26. #    Pattern to search for.
  27.     Set Pattern ""
  28. #    List of pathnames to search.
  29.     Set pathName ""
  30. #    List of options to pass to Search command.
  31.     Set Options ""
  32.  
  33. #    Loop through parameters.    
  34.     Loop
  35.         #    Break if no more parameters.
  36.             Break If "{1}" == ""
  37.         #    If parameter is an option, add to list of options.  
  38.             If "{1}" == '-f'
  39.                 Set Options "{Options} {1}"
  40.                 Shift 1
  41.                 If "{1}"
  42.                     Set Options "{Options} {1}"
  43.                 End    
  44.             Else If "{1}" =~ /∂-[bisqr]/ || "{1}" =~ /∂-n[fs]/ || "{1}" =~ /∂-sf/
  45.                 Set Options "{Options} {1}"
  46.             Else If "{1}" =~ /∂-≈/
  47.                 Echo "### {0}: ∂"{1}∂" is not an option."
  48.                 Echo "### Usage: {0} pattern [pathName…][-b][-i|-s][-nf][-ns][-sf][-q][-r][-f file]"
  49.                 Exit 1
  50.         #    If no pattern has been specified, set the pattern to the current parameter.        
  51.             Else If "{Pattern}" == ""
  52.                 Set Pattern "{1}"
  53.         #    Otherwise, add the parameter to the list of path names.
  54.             Else 
  55.                 Set pathName  "{pathName} '{1}'"
  56.             End
  57.         #    Get the next parameter.
  58.             Shift 1
  59.     End
  60.  
  61. #    If no pattern was specified, write error message and exit script.    
  62.     If "{Pattern}" == ""
  63.         Echo "### {0}: No pattern to match."
  64.         Echo "### Usage: {0} pattern [pathName…][-b][-i|-s][-nf][-ns][-sf][-q][-r][-f file]"
  65.         Exit 1
  66.     End >> Dev:StdErr
  67.     
  68. #    If no path name was specified, set pathName to the current directory.    
  69.     If "{pathName}" == ""
  70.         Set pathName "`directory`"
  71.     End
  72.  
  73. #    Loop through list of path names.    
  74.     For path in {pathName}
  75.         #    If the path name is valid, write progress info to standard output, and recursively search all 
  76.         #    files and folders within the path.
  77.             If "`Exists "{path}"`" 
  78.                 Echo "# Searching ∂"{path}∂" for {Pattern}"
  79.                 Search "{Pattern}" `files -t TEXT -r -f "{path}"` {Options} ≥ Dev:Null
  80.                 Echo
  81.         #    Otherwise, write an error message and go on to next iteration of loop.
  82.             Else 
  83.                 Echo "### {0}: {path} is not a valid pathname.∂n" >> Dev:StdErr
  84.                 Continue
  85.             End
  86.     End